<template>
	<component ref="wyObject" :is="Form" :formData="wyform" :rules="rules" :save="save"></component>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { post, get } from '@/axios'
import { ElMessage } from 'element-plus'
import Form from './components/form'
const props = defineProps(['getTable', 'id', 'urls'])
const emits = defineEmits(['update:show'])
const wyObject = ref()
const wyform = reactive({
	roomNo: null,
	remarks: '',
	bedNo: ''
})
const rules = {
	bedNo: [
		{ required: true, message: '请输入床位编号', trigger: 'blur' },
		{ max: 20, message: '床位编号最多20个字符', trigger: 'blur' }
	],
	remarks: [
		{ required: true, message: '请输入床位备注', trigger: 'blur' },
		{ max: 255, message: '床位备注最多255个字符', trigger: 'blur' }
	],
	roomNo: [
		{ required: true, message: '请输入房间号', trigger: 'blur' }
	]
}
if (props.id) {
	get(props.urls.getById, { id: props.id }, content => {
		for (const key in wyform) {
			wyform[key] = content[key]
		}
		wyform.id = props.id
	})
}
function save() {
	post(props.id ? props.urls.update : props.urls.add, wyform, content => {
		emits('update:show', false)
		props.getTable()
	}, wyObject.value.formObj)
}
</script>

<style scoped lang="scss">
</style>